﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <link href="{{ asset('myadmin/css/plugins/treeview/bootstrap-treeview.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dataTables/dataTables.bootstrap.css') }}" rel="stylesheet"><link href="{{ asset('myadmin/css/plugins/treeview/bootstrap-treeview.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
@stop
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>基本 <small>分类，查找</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="table_data_tables.html#">选项1</a>
                                </li>
                                <li><a href="table_data_tables.html#">选项2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th style="display: none">></th>
                                <th>商铺</th>
                                <th>LOGO</th>
                                <th>账号</th>
                                <th>地址</th>
                                <th>商铺详情</th>
                                <th>状态</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach(json_decode($list,true) as $k=>$v)
                                <tr class="gradeX" id="{{ $k+1 }}">
                                    <td>{{ $k+1 }}</td>
                                    <td style="display: none">{{ $v['id'] }}</td>
                                    <td>{{ $v['name'] }}</td>
                                    @if (count($v['logo'] ))
                                        <td><a data-toggle="modal"  href="#modal-form-photo" onclick="editImg(this)"><img src="{{ url('/upload/store/'.$v['logo']) }}" width="60" onclick="subHid(this)"></a></td>
                                    @else
                                        <td><a  data-toggle="modal" class="btn btn-primary" href="#modal-form-photo" onclick="subHid(this)">添加LOGO</a></td>
                                    @endif
                                    <td>{{ $v['username'] }}</td>
                                    <td>
                                        <div id="{{ 'treeview'.$k }}" class="test">

                                        </div>
                                    </td>
                                    <td><a  class="btn btn- " data-toggle="modal"  href="#modal-form" onclick="detail(this)">查看</a>
                                    <a class="btn btn-primary" href="/admin/store/{{ $v['id'] }}/edit" >修改</a></td>
                                    <td class="center">
                                        @if($v['status']==1)
                                            <a  class="btn btn-primary" onclick="delType(this)">开张</a>
                                        @else
                                            <a  class="btn btn-default" onclick="delType(this)">关门</a>
                                        @endif
                                    </td>


                                </tr>
                            @endforeach

                            </tbody>

                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>
    <div id="modal-form-photo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <button class="close"
                                    data-dismiss="modal">&times;
                            </button>
                            <h3 class="m-t-none m-b" id="up_img">添加图片</h3>

                            <form action='/admin/store/editLogo' method='post' enctype='multipart/form-data'>
                                <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                                <input type='hidden' name='id' id="hid">
                                <div class="list list-title">

                                    <li class="head"><i>我的头像：</i><img id="pic" src="" width="80"><input style="display: none" type="file" id="img" name="photo" ><button type="button" onclick="demo();"  >点击上传<br></button></li>
                                    </ul>

                                </div>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
                                ><strong>提交</strong>
                                </button>
                            </form>



                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="modal-form" class="modal fade" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12 ">
                            <button class="close"
                                    data-dismiss="modal">&times;
                            </button>

                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <form class="form-horizontal m-t" id="commentForm" action="/admin/store" method="post" enctype='multipart/form-data'>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">商家名：</label>
                                            <div class="col-sm-6 ">
                                                <input type="text" name="name" class="form-control" disabled >
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">账号：</label>
                                            <div class="col-sm-6">
                                                <input type="text" name="username" class="form-control" disabled >
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">联系方式：</label>
                                            <div class="col-sm-6">
                                                <input type="text" name="phone" class="form-control" disabled >
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">店铺简介：</label>
                                            <div class="col-sm-8">
                                                <textarea id="ccomment" name="comment" class="form-control" required="" aria-required="true" disabled ></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">具体地址：</label>
                                            <div class="col-sm-8">
                                                <textarea  name="address" class="form-control" disabled required="" aria-required="true"></textarea>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
@stop
@section('script')
    <script src="{{ asset('myadmin/js/plugins/iCheck/icheck.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>
    <!-- Bootstrap-Treeview plugin javascript -->
    <script src="{{ asset('myadmin/js/plugins/treeview/bootstrap-treeview.js') }}"></script>
    <!-- Custom and plugin javascript -->
    <script src="{{ asset('myadmin/js/hplus.js?v=2.2.0') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/pace/pace.min.js') }}"></script>
    <script>
        @foreach(json_decode($list) as $k=>$v)
             $('{{ '#treeview'.$k }}').treeview({
                levels: 1,
                {!! 'data:'.$v->path !!}
        });
        @endforeach
    </script>
    <script>
        function delType(obj) {
            if($(obj).html()=='开张'){
                var str = "确定要关门吗亲！";
            }else{
                var str = "确定要开张吗亲！";
            }

            if(confirm(str)){
                //alert("点击了确认按钮");
                ob = obj;
                td = $(ob).parent();
                var id = $(obj).parent().parent().children('td').eq(1).html();
                //alert(id);
                $.ajax({
                    url: '{{url("admin/store/status")}}',
                    type: 'POST',
                    dataType: 'json',
                    cache: false,
                    data: {_token: "{{ csrf_token() }}", id: id },
                    success: function (data) {
                        if(data>0){
                            if($(ob).html()=='开张'){
                                $(ob).remove();
                                $(td).append('<a  class="btn btn-default" onclick="delType(this)">关门</a>')


                            }else{
                                $(ob).remove();
                                $(td).append('<a  class="btn btn-primary" onclick="delType(this)">开张</a>');
                            }


                        }

                        // alert(data);
                        // $('#modal-form-one').modal('hide');

                    },
                });
            }
            else{

                //alert("点击了取消按钮");

            }

        }
        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
        function subHid(obj) {
            //获取原节点id
            hid = $(obj).parentsUntil('#tbody').children('td').eq(1).html();
            //did =  $(obj).parent().parent().attr('id');
            src = $(obj).attr('src');
            //把原节点名添加到模态框
            $('#pic').attr('src',src);
            //把原节点名添加到模态框
            $('#hid').val(hid);
        }

        function editImg(obj){
            //did =  $(obj).parent().parent().attr('id');
            $('#up_img').html('更改图片');

        }
        function detail(obj) {


            //alert("点击了确认按钮");
            var id = $(obj).parentsUntil('#tbody').children('td').eq(1).html();

            //alert(id);
            $.ajax({
                url: '{{url("admin/store/detail")}}',
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: {_token: "{{ csrf_token() }}", id: id},
                success: function (data) {
                    //alert(data.info);
                    $("input[name='name']").attr("value",data.name);
                    $("input[name='username']").attr("value",data.username);
                    $("input[name='phone']").attr("value",data.phone);
                    $("textarea[name='comment']").html(data.info);
                    $("textarea[name='address']").html(data.address);


                },
                error: function (data) {

                },
            });
        }

    </script>
    <script>
        $(document).ready(function () {
            $('.dataTables-example').dataTable();

            /* Init DataTables */
            var oTable = $('#editable').dataTable();

            /* Apply the jEditable handlers to the table */
            oTable.$('td').editable('../example_ajax.php', {
                "callback": function (sValue, y) {
                    var aPos = oTable.fnGetPosition(this);
                    oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                },
                "submitdata": function (value, settings) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition(this)[2]
                    };
                },

                "width": "90%",
                "height": "100%"
            });


        });

        function fnClickAddRow() {
            $('#editable').dataTable().fnAddData([
                "Custom row",
                "New row",
                "New row",
                "New row",
                "New row"]);

        }
    </script>

@stop